package cn.com.hhrcw.vo;

import cn.com.hhrcw.entity.OpDeliveryHistory;
import cn.com.hhrcw.utils.DateUtil;
import lombok.Data;
import org.springframework.util.CollectionUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: recruit-boot-parent
 * @author: JD
 * @create: 2020-10-31 15:53
 **/
@Data
public class IndexProgressVO {

    /**
     * 在招职位数
     */
    private Integer onLineJobCount;

    /**
     * 计划招聘人数
     */
    private Integer planCount;

    /**
     * 剩余待招人数
     */
    private Integer surplusCount;

    /**
     * 筛选简历数
     */
    private Integer screenCount;

    /**
     * 初筛数量
     */
    private Integer firstStepScreenCount;

    /**
     * 面试数量
     */
    private Integer interviewCount;

    /**
     * 已面试
     */
    private Integer alreadyInterviewCount;

    /**
     * 已发入职通知 offer
     */
    private Integer alreadyNoticeCount;

    /**
     * 已入职数量
     */
    private Integer alreadyEntryCount;

    /**
     * 近七天简历数量
     */
    List<Integer> nearlySevenDays;

    Map<Integer, Integer> sevenMap;

    public void doSevenDays(List<OpDeliveryHistory> histories) {
        if (!CollectionUtils.isEmpty(histories)) {
            sevenMap = new LinkedHashMap<>();
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            int days = 7;
            for (Integer i = 1; i <= days; i++) {
                String time = DateUtil.getDayString(i - 1);
                Integer count = sevenMap.get(i) == null ? 0 : sevenMap.get(i);
                try {
                    long statMil = format.parse(time).getTime();
                    long endMil = statMil + 86400000;
                    for (OpDeliveryHistory e : histories) {
                        if (e.getCreateTime().getTime() >= statMil && e.getCreateTime().getTime() < endMil) {
                            count = count + 1;
                        }
                    }
                    sevenMap.put(i, count);
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
        }

    }

}
